using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using SysCommon.Entity.Business;
using SysCommon.Tools;

namespace TMSIM.Client.CM.Src.CM.Business
{
    public class RowComparer : System.Collections.IComparer
    {
        private static int sortOrderModifier = 1;

        public RowComparer(SortOrder sortOrder)
        {
            if (sortOrder == SortOrder.Descending)
            {
                sortOrderModifier = -1;
            }
            else if (sortOrder == SortOrder.Ascending) { sortOrderModifier = 1; }
        }
        public int Compare(object x, object y)
        {
            string id =SetColumn.SetColumnID;
            LatestGPS_Ety LatestGPS_Ety1 = (SysCommon.Entity.Business.LatestGPS_Ety)x;
            LatestGPS_Ety LatestGPS_Ety2 = (SysCommon.Entity.Business.LatestGPS_Ety)y;
            int CompareResult;
            if (id == "DATEDMYTIME")
            {
                CompareResult = System.DateTime.Compare(
                           Convert.ToDateTime(TypeOperation.GetPropertyValue(LatestGPS_Ety1, id)), Convert.ToDateTime(TypeOperation.GetPropertyValue(LatestGPS_Ety2, id)));

            }
            // Try to sort based on the Last Name column.
            else if (id == "SPEED")
            {
                CompareResult = Convert.ToInt16(TypeOperation.GetPropertyValue(LatestGPS_Ety1, id))-Convert.ToInt16(TypeOperation.GetPropertyValue(LatestGPS_Ety2, id));
            }

            else
            {
                CompareResult = System.String.Compare(
                 TypeOperation.GetPropertyValue(LatestGPS_Ety1, id).ToString(), TypeOperation.GetPropertyValue(LatestGPS_Ety2, id).ToString());
            }

            string s = TypeOperation.GetPropertyValue(LatestGPS_Ety1, id).ToString();
            // If the Last Names are equal, sort based on the First Name.
            if (CompareResult == 0)
            {
                CompareResult = System.String.Compare(
                  TypeOperation.GetPropertyValue(LatestGPS_Ety1, id).ToString(), TypeOperation.GetPropertyValue(LatestGPS_Ety2, id).ToString());
            }
            return CompareResult * sortOrderModifier;
        }
        /***public int Compare(object x, object y)
        {
            int id = SetColumn.SetColumnID;
            DataGridViewRow DataGridViewRow1 = (DataGridViewRow)x;
            DataGridViewRow DataGridViewRow2 = (DataGridViewRow)y;

            // Try to sort based on the Last Name column.
            int CompareResult = System.String.Compare(
                DataGridViewRow1.Cells[id].Value.ToString(),
                DataGridViewRow2.Cells[id].Value.ToString());

            // If the Last Names are equal, sort based on the First Name.
            if (CompareResult == 0)
            {
                CompareResult = System.String.Compare(
                    DataGridViewRow1.Cells[id].Value.ToString(),
                    DataGridViewRow2.Cells[id].Value.ToString());
            }
            return CompareResult * sortOrderModifier;
        }***/
    }

  }

    
